//
//  ViewController.m
//  DDEasyScrollCardDemo
//
//  Created by 搭搭 on 2022/3/23.
//

#import "ViewController.h"

#import "DDEasyScrollCard.h"

@interface ViewController ()<DDEasyScrollCardDataSource,DDEasyScrollCardDelegate>

@property (nonatomic,weak)DDEasyScrollCard *card;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    CGFloat xvalue = 20;
    CGFloat width = self.view.bounds.size.width-2*xvalue;
    CGFloat height = width * 0.65;

    DDEasyScrollCard *cardView = [[DDEasyScrollCard alloc]initWithFrame:CGRectMake(xvalue, 100, width, height)];
    cardView.dataSource = self;
    cardView.delegate = self;
    // 设置是否可以无限轮回
    cardView.backgroundColor = UIColor.redColor;
    self.card = cardView;
    [self.view addSubview:cardView];
    
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(100, CGRectGetMaxY(cardView.frame)+100, 100, 50)];
    btn.backgroundColor = UIColor.greenColor;
    [self.view addSubview:btn];
    [btn addTarget:self action:@selector(clickToNextController) forControlEvents:UIControlEventTouchUpInside];
    
}

#pragma mark - DDEasyScrollCardDataSource
- (NSInteger)overlapCountOfEasyScrollCard:(DDEasyScrollCard *)card
{
    return 2;
}

- (NSArray<NSString *> *)cardListOfEasyScrollCard:(DDEasyScrollCard *)card
{
    return @[
        @"https://img2.baidu.com/it/u=121102239,1207969661&fm=253&fmt=auto&app=120&f=JPEG?w=1195&h=500",
        @"https://img0.baidu.com/it/u=68353154,235073569&fm=253&fmt=auto&app=120&f=JPEG?w=1200&h=675",
        @"https://img1.baidu.com/it/u=3097007933,3775451098&fm=253&fmt=auto&app=120&f=JPEG?w=1200&h=750",
        @"https://img1.baidu.com/it/u=4163046217,449490696&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=281",
        @"https://img1.baidu.com/it/u=1791117824,3779361334&fm=253&fmt=auto&app=120&f=JPEG?w=1422&h=800"
    ];
}

#pragma mark - DDEasyScrollCardDelegate
- (void)easyCard:(DDEasyScrollCard *)easyCard itemClickWithIndex:(NSInteger)index
{
    NSLog(@"点击了卡片: %ld",index);
}

- (void)easyCard:(DDEasyScrollCard *)easyCard willBeginScrollWithIndex:(NSInteger)index
{
    NSLog(@"将要拖动卡片: %ld",index);
}

- (void)easyCard:(DDEasyScrollCard *)easyCard willEndScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex
{
    NSLog(@"将要结束拖动卡片: 来自: %ld,  前往： %ld",fromIndex,toIndex);
}


- (void)clickToNextController
{
    UIViewController *testVc = [[UIViewController alloc]init];
    testVc.title = @"测试";
    testVc.view.backgroundColor = UIColor.whiteColor;
    [self.navigationController pushViewController:testVc animated:true];
    
}



@end
